#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

vector<vector<int> > adj;
struct node
{
	int v;
	node* parent;
	vector <node*> child;
}
int n;

void DFS(int u)
{
	for (int i = 0; i < adj[u].size(); i++) 
	{
			
	}
}

int main()
{
	while (cin >> n)
	{		
		adj.resize(n);

		for (int i = 0; i < n; i++) 
		{
			int m, k;
			scanf("%d:(%d)", &m, &k);
			adj[m].resize(0);

			for (int j = 0; j < k; j++) 
			{
				scanf("%d", &p);
				adj[m].push_back(p);
				deg[p]++;
			}
		}
		
		int root = -1;
		for (int i = 0; i < n; i++) 
			if (deg[i] == 0) 
			{
				root = i;
				break;
			}
		DFS(root);

		char c;
		int npair;
		cin >> npair;
		for (int i = 0; i < npair; i++) 
		{
			cin >> c >> u >> v >> c;
			mark(u, 1);
		}
	}
	return 0;
}
